package com.wangzhen.spring.bean.definition;

import com.wangzhen.spring.ioc.dependcy.entity.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * bean实例化演示demo
 * @author dell
 * @since 2020/10/27 8:26
 */
public class BeanInstantiationDemo {

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:/META-INF/bena-instantiation-context.xml");
        // 通过User类的静态方法来创建对象
        User bean = context.getBean("use-by-static-method", User.class);
        System.out.println(bean);
        // 通过工厂方法来创建对象
        /*User bean1 = context.getBean("user-by-factory-method", User.class);
        System.out.println(bean1);*/
        // 通过实现FactoryBean接口来获取bean对象
        User bean2 = context.getBean("use-by-factory-bean", User.class);
        System.out.println(bean2);

        System.out.println(context);
    }
}
